const {app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');


let mapWindow;
function createMapWindow() {
    mapWindow = new BrowserWindow({
        x: 100,
        y: 50,
        show: false,
        width: 800,
        height: 600,
        alwaysOnTop: true,
        autoHideMenuBar: true,
        title: '地图',
        webPreferences: {
            preload: path.join(__dirname, '/script/mapPage_preload.js')
        }
    });

    mapWindow.once('ready-to-show', () => {
        mapWindow.show();
    });
    mapWindow.on('closed', () => {
        mapWindow = null;
    });
    mapWindow.loadFile(path.join(__dirname, '/mapPage.html'));

    // mapWindow.webContents.openDevTools();
    
}

let totalMapWindow;
function createTotalMapWindow(mainWindow) {
    totalMapWindow = new BrowserWindow({
        x: 100,
        y: 50,
        show: false,
        width: 800,
        height: 600,
        alwaysOnTop: true,
        autoHideMenuBar: true,
        title: '地图',
        webPreferences: {
            preload: path.join(__dirname, '/script/totalMapPage_preload.js')
        }
    });

    totalMapWindow.once('ready-to-show', () => {
        mainWindow.hide();//隐藏主窗口
        totalMapWindow.show();
    });
    totalMapWindow.on('closed', () => {
        mainWindow.show();
        totalMapWindow = null;
    });
    totalMapWindow.loadFile(path.join(__dirname, '/totalMapPage.html'));

    // totalMapWindow.webContents.openDevTools();
    
}

//*************进程间通信**********/
ipcMain.on('save_position_obj', (event,obj) => {
    require('../temp/various').currentMapPoi_Ele.poi= obj;
});
ipcMain.handle('get_position_obj', (event) => {
    return require('../temp/various').currentMapPoi_Ele.poi;
});
//返回上车点名称
ipcMain.handle('get_place_title', (event) => {
    return require('../temp/various').currentMapPoi_Ele.placeTitle;
});




module.exports = {
    createMapWindow,
    createTotalMapWindow,
    mapWindow,
    totalMapWindow
};